package com.halixun.d2app.adapter.holder;

import android.util.Log;
import android.view.View;
import android.widget.CheckBox;

import com.halixun.d2app.R;
import com.halixun.d2app.adapter.FootTypeAdapter;
import com.halixun.d2app.base.BaseViewHolder;
import com.halixun.d2app.bean.FoodCategoryInfo;

/**
 * @ProjectName: D2App
 * @Package: com.halixun.d2app.adapter.holder
 * @ClassName: FootTypeViewHolder
 * @Description: java类作用描述
 * @Author: hdx
 * @CreateDate: 2019/12/9 18:20
 * @UpdateUser: hdx
 * @UpdateDate: 2019/12/9 18:20
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class FootTypeViewHolder extends BaseViewHolder<FoodCategoryInfo> {

    private CheckBox mCheckBox;

    private FootTypeAdapter.FootTypeListener mListener;

    private FoodCategoryInfo data;

    public FootTypeViewHolder(View itemView) {
        super(itemView);
        initView();
        setLiosteners();
    }

    public FootTypeViewHolder(View itemView, FootTypeAdapter.FootTypeListener listener) {
        this(itemView);
        this.mListener = listener;
    }

    private void setLiosteners() {
        mCheckBox.setOnCheckedChangeListener((buttonView,isChecked)->{
            if (null!=mListener&&null!=data){
                data.setSelected(isChecked);
                mListener.onFootTypeListener(getAdapterPosition());
            }
        });
    }

    private void initView() {
        mCheckBox = itemView.findViewById(R.id.mCheckBox);
    }

    @Override
    public void setLayoutInfo(FoodCategoryInfo info) {
        this.data = info;
        mCheckBox.setText(info.getClassName());
        mCheckBox.setChecked(info.isSelected());
    }
}
